package week07.necessary.service.impl;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import week07.necessary.annotation.DsReadOnly;
import week07.necessary.service.IOrdersService;

import javax.annotation.Resource;

@Service
public class OrdersServiceImpl implements IOrdersService {
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    @DsReadOnly
    public int orderCount() {
        return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM orders", Integer.class);
    }

    @Override
    public boolean updateStateById(int state, int id) {
        return jdbcTemplate.update("UPDATE orders set state = ? WHERE id = ?", state, id) > 0;
    }
}
